﻿using System;
using System.Data;
using LibDBConnect;

namespace LibDataLayer
{
    public static class DalPostsMini
    {
        private static readonly SqlHelper Cls = new SqlHelper();
        #region[Get-Data]
        public static DataTable GetPostsMini(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            return Cls.GetData("sp_PostsMini_Get");
        }
        public static DataTable GetPostsMiniEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pmid", id);
            return Cls.GetData("sp_PostsMini_Get_Edit");
        }
        public static DataTable GetPostsMiniFillterStatus(int IsActive)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("IsActive", IsActive);
            return Cls.GetData("sp_PostsMini_Get_FillterStatus");
        }
        public static DataTable GetPostsMiniFillterCategories(int Tmid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tmid", Tmid);
            return Cls.GetData("sp_PostsMini_Get_FillterCategories");
        }
        public static DataTable GetPostsFillterDate(string DateBegin, string DateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("DateBegin", DateBegin);
            Cls.AddParameter("EndBegin", DateEnd);
            return Cls.GetData("sp_PostsMini_Get_FillterDate");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(DTOPostsMini obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId", obj.UserId);
            Cls.AddParameter("UserIp", obj.UserIp);
            Cls.AddParameter("Message", obj.Message);
            Cls.AddParameter("HideSmiles", obj.HideSmiles);
            Cls.AddParameter("Posted", obj.Posted);
            Cls.AddParameter("EditedBy", obj.EditedBy);
            Cls.AddParameter("Tmid", obj.Tmid);
            return Cls.ExecuteNonQuery("sp_PostsMini_Insert");
        }
        public static bool Update(DTOPostsMini obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pmid", obj.Pmid);
            Cls.AddParameter("UserIp", obj.UserIp);
            Cls.AddParameter("Message", obj.Message);
            Cls.AddParameter("HideSmiles", obj.HideSmiles);
            Cls.AddParameter("Edited", obj.Edited);
            Cls.AddParameter("EditedBy", obj.EditedBy);
            Cls.AddParameter("Tmid", obj.Tmid);
            return Cls.ExecuteNonQuery("sp_PostsMini_Update");
        }
        public static bool Delete(DTOPostsMini obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pmid ", obj.Pmid);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_PostsMini_Delete", "@Msg");
            return true;
        }
        public static bool UpdateCheck(DTOPostsMini obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Pmid", obj.Pmid);
            Cls.AddParameter("IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_PostsMini_Update_Check");
        }
        public static bool InsertHomePage(DTOTopicsMini obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId", obj.UserId);
            Cls.AddParameter("Subject", obj.Subject);
            Cls.AddParameter("Posted", obj.Posted);
            Cls.AddParameter("NumViews", obj.NumViews);
            Cls.AddParameter("Fmid", obj.Fmid);
            Cls.AddParameter("Message", obj.Message);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_TopicsMini_Insert_HomePage", "@Msg");
            return true;
        }
        #endregion

        #region[Get-Home-Page]
        public static DataTable GetPostsHomePageMini(string keywords, int Tmid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            Cls.AddParameter("Tmid", Tmid);
            return Cls.GetData("sp_PostsMini_Get_HomePage");
        }
        #endregion
    }
    public class DTOPostsMini
    {
        public string UserId { get; set; }
        public int ? Pmid { get; set; }
        public string UserIp { get; set; }
        public string Message { get; set; }
        public int ? HideSmiles { get; set; }
        public DateTime Posted { get; set; }
        public DateTime Edited { get; set; }
        public string EditedBy { get; set; }
        public int ? Tmid { get; set; }
        public bool IsActive { get; set; }
        public int Msg { get; set; }
    }
}